package com.xrit.sunnyday.job;

import com.alibaba.dubbo.config.annotation.Reference;
import com.xrit.sunnyday.service.SetMealService;
import com.xrit.sunnyday.utils.QiNiuUtils;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("cleanImgJob")
public class CleanImgJob {
    @Reference
    private SetMealService setMealService;

    public void cleanImg(){
        //查出七牛云的所有图片
        List<String> imgIn7Niu = QiNiuUtils.listFile();
        //查询数据库的所有图片
        List<String> imgInDb = setMealService.findImgs();
        //删除数据库有的，剩下垃圾图片
        imgIn7Niu.removeAll(imgInDb);
        // 删除7牛上的垃圾图片
        String[] strings = imgIn7Niu.toArray(new String[]{});
        QiNiuUtils.removeFiles(strings);
    }
}
